
package trim.testalgorithms.optresttrim;

import trim.common.Format;
import trim.common.Material;
import trim.common.inputdata.FormatOrder;
import trim.common.inputdata.MaterialStock;
import trim.differentmaterials.coefficients.Coefficients;
import trim.differentmaterials.core.NoSolutionsException;
import trim.differentmaterials.core.RestTrimmer;
import trim.differentmaterials.core.TrimCore;
import trim.differentmaterials.generator.core.Generator;

/**
 *
 * @author Podorov Alexander
 */

public class ErnmOptimalRestTrimmer extends RestTrimmer
{
    private Coefficients coefficients;
    
    public ErnmOptimalRestTrimmer(TrimCore core, Generator generator, Coefficients coefficients)
    {
        super(core, generator);
        this.coefficients = coefficients;
    }

    @Override
    public void start() throws NoSolutionsException
    {
        setFormatRests();
        setMaterialRests();

        FormatOrder[] order1 = new FormatOrder[formatCount];
        FormatOrder[] order2 = new FormatOrder[formatCount];
        for (int i = 0; i < formatCount; i++)
        {
            order1[i] = new FormatOrder(new Format(formatOrder[i].getFormat()), formatRests[i]);
            order2[i] = new FormatOrder(new Format(formatOrder[i].getFormat()), formatRests[i]);
        }

        MaterialStock[] stock1 = new MaterialStock[materialCount];
        MaterialStock[] stock2 = new MaterialStock[materialCount];
        for (int i = 0; i < materialCount; i++)
        {
            stock1[i] = new MaterialStock(new Material(materialStock[i].getMaterial()), materialRests[i]);
            stock2[i] = new MaterialStock(new Material(materialStock[i].getMaterial()), materialRests[i]);
        }

        FirstTrimmer trimmer1 = new FirstTrimmer(stock1, order1, false);
        trimmer1.fillMaterialsList();

        SecondTrimmer trimmer2 = new SecondTrimmer(trimmer1.getCombination(), order2, stock2, patterns, coefficients);
        trimmer2.process();
    }
}
